package Homework_03_31;

class Player
{
    private static int cout = 0;   //创建一个对象会加一
    private static int num = 11;   //最多创建数量
    private String name;
    private int age;
    private String sex;
    private Player()//空参构造器
    {
        cout++;
    }
    private Player(String name, int age, String sex)//有参构造器
    {
        this.name = name;
        this.age = age;
        this.sex = sex;
        cout++;
    }

    public static Player createNewPlayer() //创建无参对象
    {
        if(cout < num)
        {
            return new Player();
        }
        else
        {
            return null;
        }
    }

    public static Player creatNewPlayer(String name, int age, String sex)//创建有参对象
    {
        if(cout < num)
        {
            return new Player(name, age, sex);
        }
        else
        {
            return null;
        }
    }

    public static int getCout() {
        return cout;
    }

    public static void setCout(int cout) {
        Player.cout = cout;
    }

    public static int getNum() {
        return num;
    }

    public static void setNum(int num) {
        Player.num = num;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }
}


public class Main1 {
    public static void main(String[] args) {
        while(true)
        {
            Player player = Player.createNewPlayer();
            if(player == null)
            {
                System.out.println("已经创建了" + Player.getNum() + "个对象");
                break;
            }
            else
            {
                System.out.println("创建了第" + Player.getCout() + "个球员");
            }
        }
    }
}
